{
 "metadata": {
  "name": "mass_spring_damper"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Here we will derive the equations of motion for the classic mass, spring, damper system under the influence of gravity. The following figure gives a pictorial description of the problem."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from IPython.display import SVG\n",
      "SVG(filename='mass_spring_damper.svg')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "pyout",
       "prompt_number": 1,
       "svg": [
        "<svg height=\"400\" id=\"svg2\" inkscape:version=\"0.48.3.1 r9886\" sodipodi:docname=\"mass_spring_damper.svg\" version=\"1.1\" width=\"400\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" xmlns:ns0=\"http://www.iki.fi/pav/software/textext/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
        "  <sodipodi:namedview bordercolor=\"#666666\" borderopacity=\"1.0\" id=\"base\" inkscape:current-layer=\"layer1\" inkscape:cx=\"200\" inkscape:cy=\"200\" inkscape:document-units=\"px\" inkscape:guide-bbox=\"true\" inkscape:pageopacity=\"0.0\" inkscape:pageshadow=\"2\" inkscape:window-height=\"744\" inkscape:window-maximized=\"1\" inkscape:window-width=\"1366\" inkscape:window-x=\"0\" inkscape:window-y=\"24\" inkscape:zoom=\"1.4125\" pagecolor=\"#ffffff\" showgrid=\"false\" showguides=\"true\"/>\n",
        "  <defs id=\"defs4\">\n",
        "    <marker id=\"Arrow1Mend\" inkscape:stockid=\"Arrow1Mend\" orient=\"auto\" refX=\"0.0\" refY=\"0.0\" style=\"overflow:visible;\">\n",
        "      <path d=\"M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z \" id=\"path4821\" style=\"fill-rule:evenodd;stroke:#000000;stroke-width:1.0pt;\" transform=\"scale(0.4) rotate(180) translate(10,0)\"/>\n",
        "    </marker>\n",
        "    <marker id=\"Arrow1Lend\" inkscape:stockid=\"Arrow1Lend\" orient=\"auto\" refX=\"0.0\" refY=\"0.0\" style=\"overflow:visible;\">\n",
        "      <path d=\"M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z \" id=\"path4815\" style=\"fill-rule:evenodd;stroke:#000000;stroke-width:1.0pt;\" transform=\"scale(0.8) rotate(180) translate(12.5,0)\"/>\n",
        "    </marker>\n",
        "  </defs>\n",
        "  <metadata id=\"metadata7\">\n",
        "    <rdf:RDF>\n",
        "      <cc:Work rdf:about=\"\">\n",
        "        <dc:format>image/svg+xml</dc:format>\n",
        "        <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
        "        <dc:title/>\n",
        "      </cc:Work>\n",
        "    </rdf:RDF>\n",
        "  </metadata>\n",
        "  <g id=\"layer1\" inkscape:groupmode=\"layer\" inkscape:label=\"Layer 1\" transform=\"translate(0,-652.36218)\">\n",
        "    <path d=\"m 275.66301,434.91428 c 0,19.03056 -7.50518,34.45787 -16.76329,34.45787 -9.25811,0 -16.76329,-15.42731 -16.76329,-34.45787 0,-19.03056 7.50518,-34.45788 16.76329,-34.45788 9.25811,0 16.76329,15.42732 16.76329,34.45788 z\" id=\"path2985\" sodipodi:cx=\"258.89972\" sodipodi:cy=\"434.91428\" sodipodi:rx=\"16.763292\" sodipodi:ry=\"34.457878\" sodipodi:type=\"arc\" style=\"fill:#000000;stroke:#ffffff;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0\" transform=\"matrix(2.2459897,0,0,1.0926436,-383.96398,479.35965)\"/>\n",
        "    <path d=\"m 65.840708,706.87545 260.530972,0\" id=\"path2987\" inkscape:connector-curvature=\"0\" style=\"fill:none;stroke:#000000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 196.6927,949.24229 0,-55.92921\" id=\"path2989\" inkscape:connector-curvature=\"0\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 146.54867,178.40708 0,62.30088 95.57522,0 0,-30.07807\" id=\"path2991\" inkscape:connector-curvature=\"0\" sodipodi:nodetypes=\"cccc\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\" transform=\"translate(0,652.36218)\"/>\n",
        "    <path d=\"m 120.02515,864.37368 0,-73.62832 53.09735,0 0,72.97678\" id=\"path2993\" inkscape:connector-curvature=\"0\" sodipodi:nodetypes=\"cccc\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 146.72783,707.1687 0,82.6184\" id=\"path2995\" inkscape:connector-curvature=\"0\" sodipodi:nodetypes=\"cc\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 217.38072,856.8069 50.74471,-13.597\" id=\"path2999\" inkscape:connector-curvature=\"0\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 268.11464,843.20326 -50.74471,-13.597\" id=\"path2999-1\" inkscape:connector-curvature=\"0\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 217.55238,829.4259 50.74471,-13.597\" id=\"path2999-3\" inkscape:connector-curvature=\"0\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 268.2863,815.82226 -50.74471,-13.597\" id=\"path2999-1-3\" inkscape:connector-curvature=\"0\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 218.053,802.39313 50.74471,-13.597\" id=\"path2999-3-2\" inkscape:connector-curvature=\"0\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 268.78692,788.78949 -50.74471,-13.597\" id=\"path2999-1-3-5\" inkscape:connector-curvature=\"0\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 218.5536,775.11007 50.74471,-13.597\" id=\"path2999-3-8\" inkscape:connector-curvature=\"0\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 269.28752,761.50643 -50.74471,-13.597\" id=\"path2999-1-3-1\" inkscape:connector-curvature=\"0\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 244.79661,55.082073 0,33.290336\" id=\"path3070\" inkscape:connector-curvature=\"0\" sodipodi:nodetypes=\"cc\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\" transform=\"translate(0,652.36218)\"/>\n",
        "    <path d=\"m 124.90134,830.59348 42.55156,0\" id=\"path3072\" inkscape:connector-curvature=\"0\" sodipodi:nodetypes=\"cc\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"M 242.02277,863.10943 217.67214,856.5847\" id=\"path2999-1-7\" inkscape:connector-curvature=\"0\" sodipodi:nodetypes=\"cc\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 218.67335,747.53309 26.19766,-7.01964\" id=\"path2999-3-8-9\" inkscape:connector-curvature=\"0\" sodipodi:nodetypes=\"cc\" style=\"fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none\"/>\n",
        "    <path d=\"m 94.159292,695.54802 -19.38348,11.19106\" id=\"path3897\" inkscape:connector-curvature=\"0\" inkscape:tile-cx=\"84.467552\" inkscape:tile-cy=\"48.78137\" inkscape:tile-h=\"11.19106\" inkscape:tile-w=\"19.38348\" inkscape:tile-x0=\"74.775812\" inkscape:tile-y0=\"43.18584\" style=\"fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
        "    <use id=\"use3919\" inkscape:tiled-clone-of=\"#path3897\" x=\"0\" xlink:href=\"#path3897\" y=\"0\"/>\n",
        "    <use id=\"use3935\" inkscape:tile-cx=\"84.467552\" inkscape:tile-cy=\"48.78137\" inkscape:tile-h=\"11.19106\" inkscape:tile-w=\"19.38348\" inkscape:tile-x0=\"74.775812\" inkscape:tile-y0=\"43.18584\" inkscape:tiled-clone-of=\"#path3897\" x=\"0\" xlink:href=\"#path3897\" y=\"0\"/>\n",
        "    <use id=\"use4121\" inkscape:tiled-clone-of=\"#use3935\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <use id=\"use4123\" inkscape:tiled-clone-of=\"#use3935\" transform=\"translate(19.38348,0)\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <use id=\"use4125\" inkscape:tiled-clone-of=\"#use3935\" transform=\"translate(38.76696,0)\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <use id=\"use4127\" inkscape:tiled-clone-of=\"#use3935\" transform=\"translate(58.15044,0)\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <use id=\"use4129\" inkscape:tiled-clone-of=\"#use3935\" transform=\"translate(77.53392,0)\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <use id=\"use4131\" inkscape:tiled-clone-of=\"#use3935\" transform=\"translate(96.9174,0)\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <use id=\"use4133\" inkscape:tiled-clone-of=\"#use3935\" transform=\"translate(116.30088,0)\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <use id=\"use4135\" inkscape:tiled-clone-of=\"#use3935\" transform=\"translate(135.68436,0)\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <use id=\"use4137\" inkscape:tiled-clone-of=\"#use3935\" transform=\"translate(155.06784,0)\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <use id=\"use4139\" inkscape:tiled-clone-of=\"#use3935\" transform=\"translate(174.45132,0)\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <use id=\"use4141\" inkscape:tiled-clone-of=\"#use3935\" transform=\"translate(193.8348,0)\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <use id=\"use4143\" inkscape:tiled-clone-of=\"#use3935\" transform=\"translate(213.21828,0)\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <use id=\"use4145\" inkscape:tiled-clone-of=\"#use3935\" transform=\"translate(232.60176,0)\" x=\"0\" xlink:href=\"#use3935\" y=\"0\"/>\n",
        "    <g id=\"g4309\" ns0:preamble=\"\" ns0:text=\"$m$\" transform=\"matrix(2,0,0,2,-208.26353,709.27877)\">\n",
        "      <defs id=\"defs4311\">\n",
        "        <g id=\"g4313\">\n",
        "          <symbol id=\"textext-08e211e0-0\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"\" id=\"path4316\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "          <symbol id=\"textext-08e211e0-1\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"m 0.875,-0.59375 c -0.03125,0.15625 -0.09375,0.390625 -0.09375,0.4375 0,0.171875 0.140625,0.265625 0.296875,0.265625 0.125,0 0.296875,-0.078125 0.375,-0.28125 0,-0.015625 0.125,-0.484375 0.1875,-0.734375 l 0.21875,-0.890625 C 1.90625,-2.03125 1.96875,-2.25 2.03125,-2.46875 c 0.03125,-0.171875 0.109375,-0.46875 0.125,-0.5 0.140625,-0.3125 0.671875,-1.21875 1.625,-1.21875 0.453125,0 0.53125,0.375 0.53125,0.703125 0,0.25 -0.0625,0.53125 -0.140625,0.828125 L 3.890625,-1.5 3.6875,-0.75 c -0.03125,0.203125 -0.125,0.546875 -0.125,0.59375 0,0.171875 0.140625,0.265625 0.28125,0.265625 0.3125,0 0.375,-0.25 0.453125,-0.5625 0.140625,-0.5625 0.515625,-2.015625 0.59375,-2.40625 0.03125,-0.125 0.5625,-1.328125 1.65625,-1.328125 0.421875,0 0.53125,0.34375 0.53125,0.703125 0,0.5625 -0.421875,1.703125 -0.625,2.234375 -0.078125,0.234375 -0.125,0.34375 -0.125,0.546875 0,0.46875 0.34375,0.8125 0.8125,0.8125 0.9375,0 1.3125,-1.453125 1.3125,-1.53125 0,-0.109375 -0.09375,-0.109375 -0.125,-0.109375 -0.09375,0 -0.09375,0.03125 -0.140625,0.1875 -0.15625,0.53125 -0.46875,1.234375 -1.015625,1.234375 -0.171875,0 -0.25,-0.09375 -0.25,-0.328125 0,-0.25 0.09375,-0.484375 0.1875,-0.703125 0.1875,-0.53125 0.609375,-1.625 0.609375,-2.203125 0,-0.640625 -0.40625,-1.0625 -1.15625,-1.0625 -0.734375,0 -1.25,0.4375 -1.625,0.96875 0,-0.125 -0.03125,-0.46875 -0.3125,-0.703125 -0.25,-0.21875 -0.5625,-0.265625 -0.8125,-0.265625 -0.90625,0 -1.390625,0.640625 -1.5625,0.875 -0.046875,-0.578125 -0.46875,-0.875 -0.921875,-0.875 -0.453125,0 -0.640625,0.390625 -0.734375,0.5625 -0.171875,0.359375 -0.296875,0.9375 -0.296875,0.96875 0,0.109375 0.09375,0.109375 0.109375,0.109375 0.109375,0 0.109375,-0.015625 0.171875,-0.234375 0.171875,-0.703125 0.375,-1.1875 0.734375,-1.1875 0.15625,0 0.296875,0.078125 0.296875,0.453125 0,0.21875 -0.03125,0.328125 -0.15625,0.84375 z\" id=\"path4319\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "        </g>\n",
        "      </defs>\n",
        "      <g id=\"textext-08e211e0-2\">\n",
        "        <g id=\"g4322\" style=\"fill:#000000;fill-opacity:1\">\n",
        "          <use height=\"400\" id=\"use4324\" width=\"400\" x=\"223.43201\" xlink:href=\"#textext-08e211e0-1\" y=\"134.765\"/>\n",
        "        </g>\n",
        "      </g>\n",
        "    </g>\n",
        "    <g id=\"g4422\" ns0:preamble=\"\" ns0:text=\"$c$\" transform=\"matrix(2,0,0,2,-346.05561,543.41648)\">\n",
        "      <defs id=\"defs4424\">\n",
        "        <g id=\"g4426\">\n",
        "          <symbol id=\"textext-2f24d870-0\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"\" id=\"path4429\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "          <symbol id=\"textext-2f24d870-1\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"m 3.953125,-3.78125 c -0.171875,0 -0.296875,0 -0.4375,0.125 -0.171875,0.15625 -0.1875,0.328125 -0.1875,0.390625 0,0.25 0.1875,0.359375 0.375,0.359375 0.28125,0 0.546875,-0.25 0.546875,-0.640625 0,-0.484375 -0.46875,-0.859375 -1.171875,-0.859375 -1.34375,0 -2.671875,1.421875 -2.671875,2.828125 0,0.90625 0.578125,1.6875 1.625,1.6875 1.421875,0 2.25,-1.0625 2.25,-1.171875 0,-0.0625 -0.046875,-0.140625 -0.109375,-0.140625 -0.0625,0 -0.078125,0.03125 -0.140625,0.109375 -0.78125,0.984375 -1.875,0.984375 -1.984375,0.984375 -0.625,0 -0.90625,-0.484375 -0.90625,-1.09375 0,-0.40625 0.203125,-1.375 0.546875,-1.984375 0.3125,-0.578125 0.859375,-1 1.40625,-1 0.328125,0 0.71875,0.125 0.859375,0.40625 z\" id=\"path4432\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "        </g>\n",
        "      </defs>\n",
        "      <g id=\"textext-2f24d870-2\">\n",
        "        <g id=\"g4435\" style=\"fill:#000000;fill-opacity:1\">\n",
        "          <use height=\"400\" id=\"use4437\" width=\"400\" x=\"223.43201\" xlink:href=\"#textext-2f24d870-1\" y=\"134.765\"/>\n",
        "        </g>\n",
        "      </g>\n",
        "    </g>\n",
        "    <g id=\"g4555\" ns0:preamble=\"\" ns0:text=\"$k$\" transform=\"matrix(2,0,0,2,-167.19648,535.69871)\">\n",
        "      <defs id=\"defs4557\">\n",
        "        <g id=\"g4559\">\n",
        "          <symbol id=\"textext-98de1750-0\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"\" id=\"path4562\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "          <symbol id=\"textext-98de1750-1\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"m 2.859375,-6.8125 c 0,0 0,-0.109375 -0.125,-0.109375 -0.234375,0 -0.953125,0.078125 -1.21875,0.109375 -0.078125,0 -0.1875,0.015625 -0.1875,0.1875 0,0.125 0.09375,0.125 0.234375,0.125 0.484375,0 0.5,0.0625 0.5,0.171875 L 2.03125,-6.125 0.59375,-0.390625 c -0.046875,0.140625 -0.046875,0.15625 -0.046875,0.21875 0,0.234375 0.203125,0.28125 0.296875,0.28125 0.125,0 0.265625,-0.09375 0.328125,-0.203125 0.046875,-0.09375 0.5,-1.9375 0.5625,-2.1875 0.34375,0.03125 1.15625,0.1875 1.15625,0.84375 0,0.078125 0,0.109375 -0.03125,0.21875 -0.015625,0.109375 -0.03125,0.234375 -0.03125,0.34375 0,0.578125 0.390625,0.984375 0.90625,0.984375 0.296875,0 0.578125,-0.15625 0.796875,-0.53125 0.25,-0.4375 0.359375,-0.984375 0.359375,-1 0,-0.109375 -0.09375,-0.109375 -0.125,-0.109375 -0.09375,0 -0.109375,0.046875 -0.140625,0.1875 -0.203125,0.71875 -0.421875,1.234375 -0.859375,1.234375 -0.203125,0 -0.328125,-0.109375 -0.328125,-0.46875 0,-0.171875 0.046875,-0.40625 0.078125,-0.5625 C 3.5625,-1.3125 3.5625,-1.34375 3.5625,-1.453125 3.5625,-2.09375 2.9375,-2.375 2.078125,-2.5 2.390625,-2.671875 2.71875,-2.984375 2.9375,-3.234375 3.421875,-3.765625 3.875,-4.1875 4.359375,-4.1875 c 0.0625,0 0.078125,0 0.09375,0.015625 0.125,0.015625 0.125,0.015625 0.21875,0.078125 0.015625,0 0.015625,0.015625 0.03125,0.03125 -0.46875,0.03125 -0.5625,0.421875 -0.5625,0.546875 0,0.15625 0.109375,0.34375 0.375,0.34375 0.265625,0 0.546875,-0.21875 0.546875,-0.609375 0,-0.296875 -0.234375,-0.625 -0.671875,-0.625 -0.28125,0 -0.734375,0.078125 -1.453125,0.875 -0.34375,0.375 -0.734375,0.78125 -1.109375,0.921875 z\" id=\"path4565\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "        </g>\n",
        "      </defs>\n",
        "      <g id=\"textext-98de1750-2\">\n",
        "        <g id=\"g4568\" style=\"fill:#000000;fill-opacity:1\">\n",
        "          <use height=\"400\" id=\"use4570\" width=\"400\" x=\"223.43201\" xlink:href=\"#textext-98de1750-1\" y=\"134.765\"/>\n",
        "        </g>\n",
        "      </g>\n",
        "    </g>\n",
        "    <g id=\"g4708\" ns0:preamble=\"\" ns0:text=\"$g$\" transform=\"matrix(2,0,0,2,-86.228927,567.28988)\">\n",
        "      <defs id=\"defs4710\">\n",
        "        <g id=\"g4712\">\n",
        "          <symbol id=\"textext-ee8938ff-0\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"\" id=\"path4715\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "          <symbol id=\"textext-ee8938ff-1\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"M 4.6875,-3.765625 C 4.703125,-3.8125 4.71875,-3.875 4.71875,-3.9375 c 0,-0.171875 -0.109375,-0.265625 -0.28125,-0.265625 -0.09375,0 -0.375,0.0625 -0.40625,0.421875 -0.1875,-0.359375 -0.53125,-0.625 -0.9375,-0.625 -1.125,0 -2.359375,1.390625 -2.359375,2.828125 0,0.984375 0.59375,1.578125 1.3125,1.578125 0.59375,0 1.0625,-0.46875 1.15625,-0.578125 L 3.21875,-0.5625 C 3.015625,0.3125 2.890625,0.734375 2.890625,0.75 2.84375,0.84375 2.515625,1.828125 1.453125,1.828125 1.265625,1.828125 0.9375,1.8125 0.65625,1.71875 0.953125,1.640625 1.0625,1.375 1.0625,1.203125 c 0,-0.15625 -0.109375,-0.34375 -0.375,-0.34375 -0.21875,0 -0.53125,0.171875 -0.53125,0.578125 0,0.40625 0.359375,0.609375 1.3125,0.609375 1.25,0 1.96875,-0.78125 2.125,-1.375 z M 3.40625,-1.28125 C 3.34375,-1.015625 3.109375,-0.765625 2.890625,-0.578125 2.6875,-0.40625 2.375,-0.21875 2.078125,-0.21875 c -0.5,0 -0.640625,-0.515625 -0.640625,-0.921875 0,-0.46875 0.28125,-1.65625 0.5625,-2.15625 C 2.265625,-3.78125 2.6875,-4.1875 3.109375,-4.1875 c 0.65625,0 0.796875,0.8125 0.796875,0.859375 0,0.046875 -0.015625,0.109375 -0.03125,0.140625 z\" id=\"path4718\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "        </g>\n",
        "      </defs>\n",
        "      <g id=\"textext-ee8938ff-2\">\n",
        "        <g id=\"g4721\" style=\"fill:#000000;fill-opacity:1\">\n",
        "          <use height=\"400\" id=\"use4723\" width=\"400\" x=\"223.43201\" xlink:href=\"#textext-ee8938ff-1\" y=\"134.765\"/>\n",
        "        </g>\n",
        "      </g>\n",
        "    </g>\n",
        "    <path d=\"m 83.280852,56.601681 0,243.353139\" id=\"path4802\" inkscape:connector-curvature=\"0\" sodipodi:nodetypes=\"cc\" style=\"fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow1Lend)\" transform=\"translate(0,652.36218)\"/>\n",
        "    <path d=\"m 154.66444,301.57717 -93.555763,0\" id=\"path4804\" inkscape:connector-curvature=\"0\" sodipodi:nodetypes=\"cc\" style=\"fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\" transform=\"translate(0,652.36218)\"/>\n",
        "    <path d=\"m 344.47989,178.27825 0,79.49536\" id=\"path4806\" inkscape:connector-curvature=\"0\" style=\"fill:none;stroke:#000000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow1Mend);stroke-miterlimit:4;stroke-dasharray:none\" transform=\"translate(0,652.36218)\"/>\n",
        "    <g id=\"g5706\" ns0:preamble=\"\" ns0:text=\"$x$, $v$\" transform=\"matrix(2,0,0,2,-403.90337,570.00071)\">\n",
        "      <defs id=\"defs5708\">\n",
        "        <g id=\"g5710\">\n",
        "          <symbol id=\"textext-5464613c-0\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"\" id=\"path5713\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "          <symbol id=\"textext-5464613c-1\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"M 3.328125,-3.015625 C 3.390625,-3.265625 3.625,-4.1875 4.3125,-4.1875 c 0.046875,0 0.296875,0 0.5,0.125 C 4.53125,-4 4.34375,-3.765625 4.34375,-3.515625 c 0,0.15625 0.109375,0.34375 0.375,0.34375 0.21875,0 0.53125,-0.171875 0.53125,-0.578125 0,-0.515625 -0.578125,-0.65625 -0.921875,-0.65625 -0.578125,0 -0.921875,0.53125 -1.046875,0.75 -0.25,-0.65625 -0.78125,-0.75 -1.078125,-0.75 -1.03125,0 -1.609375,1.28125 -1.609375,1.53125 0,0.109375 0.109375,0.109375 0.125,0.109375 0.078125,0 0.109375,-0.03125 0.125,-0.109375 0.34375,-1.0625 1,-1.3125 1.34375,-1.3125 0.1875,0 0.53125,0.09375 0.53125,0.671875 0,0.3125 -0.171875,0.96875 -0.53125,2.375 -0.15625,0.609375 -0.515625,1.03125 -0.953125,1.03125 -0.0625,0 -0.28125,0 -0.5,-0.125 0.25,-0.0625 0.46875,-0.265625 0.46875,-0.546875 0,-0.265625 -0.21875,-0.34375 -0.359375,-0.34375 -0.3125,0 -0.546875,0.25 -0.546875,0.578125 0,0.453125 0.484375,0.65625 0.921875,0.65625 0.671875,0 1.03125,-0.703125 1.046875,-0.75 0.125,0.359375 0.484375,0.75 1.078125,0.75 1.03125,0 1.59375,-1.28125 1.59375,-1.53125 0,-0.109375 -0.078125,-0.109375 -0.109375,-0.109375 -0.09375,0 -0.109375,0.046875 -0.140625,0.109375 -0.328125,1.078125 -1,1.3125 -1.3125,1.3125 -0.390625,0 -0.546875,-0.3125 -0.546875,-0.65625 0,-0.21875 0.046875,-0.4375 0.15625,-0.875 z\" id=\"path5716\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "          <symbol id=\"textext-5464613c-2\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"m 4.671875,-3.703125 c 0,-0.546875 -0.265625,-0.703125 -0.4375,-0.703125 -0.25,0 -0.5,0.265625 -0.5,0.484375 0,0.125 0.046875,0.1875 0.15625,0.296875 0.21875,0.203125 0.34375,0.453125 0.34375,0.8125 0,0.421875 -0.609375,2.703125 -1.765625,2.703125 -0.515625,0 -0.75,-0.34375 -0.75,-0.875 0,-0.546875 0.28125,-1.28125 0.578125,-2.109375 0.078125,-0.171875 0.125,-0.3125 0.125,-0.5 0,-0.4375 -0.3125,-0.8125 -0.8125,-0.8125 -0.9375,0 -1.3125,1.453125 -1.3125,1.53125 0,0.109375 0.09375,0.109375 0.109375,0.109375 0.109375,0 0.109375,-0.03125 0.15625,-0.1875 0.296875,-1 0.71875,-1.234375 1.015625,-1.234375 0.078125,0 0.25,0 0.25,0.3125 0,0.25 -0.109375,0.53125 -0.171875,0.703125 -0.4375,1.15625 -0.5625,1.609375 -0.5625,2.046875 0,1.078125 0.875,1.234375 1.328125,1.234375 1.671875,0 2.25,-3.296875 2.25,-3.8125 z\" id=\"path5719\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "          <symbol id=\"textext-5464613c-3\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"\" id=\"path5722\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "          <symbol id=\"textext-5464613c-4\" overflow=\"visible\" style=\"overflow:visible\">\n",
        "            <path d=\"m 2.03125,-0.015625 c 0,-0.625 -0.25,-1.046875 -0.640625,-1.046875 -0.359375,0 -0.53125,0.28125 -0.53125,0.53125 0,0.265625 0.171875,0.53125 0.53125,0.53125 0.15625,0 0.28125,-0.0625 0.375,-0.140625 L 1.78125,-0.15625 c 0.015625,0 0.015625,0 0.015625,0.140625 0,0.640625 -0.265625,1.25 -0.703125,1.71875 -0.0625,0.0625 -0.078125,0.078125 -0.078125,0.109375 0,0.078125 0.046875,0.109375 0.09375,0.109375 0.125,0 0.921875,-0.78125 0.921875,-1.9375 z\" id=\"path5725\" inkscape:connector-curvature=\"0\" style=\"stroke:none\"/>\n",
        "          </symbol>\n",
        "        </g>\n",
        "      </defs>\n",
        "      <g id=\"textext-5464613c-5\">\n",
        "        <g id=\"g5728\" style=\"fill:#000000;fill-opacity:1\">\n",
        "          <use height=\"400\" id=\"use5730\" width=\"400\" x=\"223.43201\" xlink:href=\"#textext-5464613c-1\" y=\"134.765\"/>\n",
        "        </g>\n",
        "        <g id=\"g5732\" style=\"fill:#000000;fill-opacity:1\">\n",
        "          <use height=\"400\" id=\"use5734\" width=\"400\" x=\"229.12601\" xlink:href=\"#textext-5464613c-4\" y=\"134.765\"/>\n",
        "        </g>\n",
        "        <g id=\"g5736\" style=\"fill:#000000;fill-opacity:1\">\n",
        "          <use height=\"400\" id=\"use5738\" width=\"400\" x=\"235.214\" xlink:href=\"#textext-5464613c-2\" y=\"134.765\"/>\n",
        "        </g>\n",
        "      </g>\n",
        "    </g>\n",
        "  </g>\n",
        "</svg>"
       ],
       "text": [
        "<IPython.core.display.SVG at 0x3842750>"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Start by loading in the core functionality of both SymPy and Mechanics."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import sympy as sym\n",
      "import sympy.physics.mechanics as me"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "We can make use of the pretty printing of our results by loading the SymPy printing extension."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "%load_ext sympy.interactive.ipythonprinting"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 3
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "We'll start by defining the variables will need for this problem. $x$ is the distance of the particle from the ceiling, $v$ is the speed of the particle, $m$ is the mass of the particle, $c$ is the damping coefficient of the damper, $k$ is the stiffness of the spring, $g$ is the acceleration due to gravity, and $t$ represents time."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "x, v = me.dynamicsymbols('x v')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "m, c, k, g, t = sym.symbols('m c k g t')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 5
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Now, we define a Newtonian reference frame that represents the ceiling which the particle is attached to, $C$."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "ceiling = me.ReferenceFrame('C')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 6
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "We will need two points, one to represent the original position of the particle which stays fixed in the ceiling frame, $o$, and the second one, $p$ which is aligned with the particle as it moves."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "o = me.Point('o')\n",
      "p = me.Point('p')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 7
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The velocity of point $o$ in the ceiling is zero."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "o.set_vel(ceiling, 0)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 8
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Point $p$ can move downward in the $x$ direction and it's velocity is $v$ in the downward direction."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p.set_pos(o, x * ceiling.x)\n",
      "p.set_vel(ceiling, v * ceiling.x)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 9
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "There are three forces acting on the particle. Those due to the acceleration of gravity, the damper, and the spring."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "damping = -c * p.vel(ceiling)\n",
      "stiffness = -k * p.pos_from(o)\n",
      "gravity = m * g * ceiling.x\n",
      "forces = damping + stiffness + gravity\n",
      "forces"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "pyout",
       "prompt_number": 10,
       "text": [
        "(-c\u22c5v + g\u22c5m - k\u22c5x)*\u001b[94m\u001b[1mc_x\u001b[0;0m\u001b[0;0m"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Now we can use Newton's second law, $0=F-ma$, to form the equation of motion of the system."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "zero = me.dot(forces - m * p.acc(ceiling), ceiling.x)\n",
      "zero"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "latex": [
        "$$- c \\operatorname{v}{\\left (t \\right )} + g m - k \\operatorname{x}{\\left (t \\right )} - m \\frac{\\partial}{\\partial t} \\operatorname{v}{\\left (t \\right )}$$"
       ],
       "output_type": "pyout",
       "png": "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\nm63mAAAAAElFTkSuQmCC\n",
       "prompt_number": 11,
       "text": [
        "                           d       \n",
        "-c\u22c5v(t) + g\u22c5m - k\u22c5x(t) - m\u22c5\u2500\u2500(v(t))\n",
        "                           dt      "
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "We can then form the first order equations of motion by solving for $\\frac{dv}{dt}$ and introducing the kinematical differential equation, $v=\\frac{dx}{dt}$."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "dvdt = sym.solve(zero, v.diff(t))[0]\n",
      "dxdt = v\n",
      "dvdt, dxdt"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "latex": [
        "$$\\begin{pmatrix}\\frac{- c \\operatorname{v}{\\left (t \\right )} + g m - k \\operatorname{x}{\\left (t \\right )}}{m}, & \\operatorname{v}{\\left (t \\right )}\\end{pmatrix}$$"
       ],
       "output_type": "pyout",
       "prompt_number": 12,
       "text": [
        "\u239b-c\u22c5v(t) + g\u22c5m - k\u22c5x(t)      \u239e\n",
        "\u239c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500, v(t)\u239f\n",
        "\u239d          m                 \u23a0"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Forming the equations of motion can also be done with the automated methods available in the Mechanics package: `LagrangesMethod` and `KanesMethod`. Here we will make use of Kane's method to find the same equations of motion which we found manually above. First define a particle which represents the mass attached to the damper and spring."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "mass = me.Particle('mass', p, m)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 13
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Now we can construct a `KanesMethod` object by passing in the generalized coordinate, $x$, the generalized speed, $v$, and the kinematical differential equation which relates the two, $0=v-\\frac{dx}{dt}$."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "kane = me.KanesMethod(ceiling, q_ind=[x], u_ind=[v], kd_eqs=[v - x.diff(t)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 14
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Now Kane's equations can be computed which returns $F_r$ and $F_r^*$."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "kane.kanes_equations([(p, forces)], [mass])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "latex": [
        "$$\\begin{pmatrix}\\left[\\begin{smallmatrix}c \\operatorname{v}{\\left (t \\right )} - g m + k \\operatorname{x}{\\left (t \\right )}\\end{smallmatrix}\\right], & \\left[\\begin{smallmatrix}m \\frac{\\partial}{\\partial t} \\operatorname{v}{\\left (t \\right )}\\end{smallmatrix}\\right]\\end{pmatrix}$$"
       ],
       "output_type": "pyout",
       "prompt_number": 15,
       "text": [
        "\u239b                         \u23a1  d       \u23a4\u239e\n",
        "\u239c[c\u22c5v(t) - g\u22c5m + k\u22c5x(t)], \u23a2m\u22c5\u2500\u2500(v(t))\u23a5\u239f\n",
        "\u239d                         \u23a3  dt      \u23a6\u23a0"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The equations are also available in the form $M\\frac{dq,u}{dt}=f(\\dot{u}, u, q)$ and we can extract the mass matrix, $M$, and the forcing equations, $f$."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "M = kane.mass_matrix_full\n",
      "f = kane.forcing_full\n",
      "M, f"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "latex": [
        "$$\\begin{pmatrix}\\left[\\begin{smallmatrix}1 & 0\\\\0 & m\\end{smallmatrix}\\right], & \\left[\\begin{smallmatrix}\\operatorname{v}{\\left (t \\right )}\\\\- c \\operatorname{v}{\\left (t \\right )} + g m - k \\operatorname{x}{\\left (t \\right )}\\end{smallmatrix}\\right]\\end{pmatrix}$$"
       ],
       "output_type": "pyout",
       "prompt_number": 16,
       "text": [
        "\u239b\u23a11  0\u23a4, \u23a1         v(t)         \u23a4\u239e\n",
        "\u239c\u23a2    \u23a5  \u23a2                      \u23a5\u239f\n",
        "\u239d\u23a30  m\u23a6  \u23a3-c\u22c5v(t) + g\u22c5m - k\u22c5x(t)\u23a6\u23a0"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Finally, we can form the first order differential equations of motion $\\frac{dq,u}{dt}=M^{-1}f(\\dot{u}, u, q)$, which is the same as previously found."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "M.inv() * f"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "latex": [
        "$$\\left[\\begin{smallmatrix}\\operatorname{v}{\\left (t \\right )}\\\\\\frac{- c \\operatorname{v}{\\left (t \\right )} + g m - k \\operatorname{x}{\\left (t \\right )}}{m}\\end{smallmatrix}\\right]$$"
       ],
       "output_type": "pyout",
       "prompt_number": 17,
       "text": [
        "\u23a1         v(t)         \u23a4\n",
        "\u23a2                      \u23a5\n",
        "\u23a2-c\u22c5v(t) + g\u22c5m - k\u22c5x(t)\u23a5\n",
        "\u23a2\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u23a5\n",
        "\u23a3          m           \u23a6"
       ]
      }
     ],
     "prompt_number": 17
    }
   ],
   "metadata": {}
  }
 ]
}